package com.maserb.monitor.web.personal;

import com.maserb.monitor.common.*;
import com.maserb.monitor.entity.UserEntity;
import com.maserb.monitor.entity.personal.SchoolAdviseEntity;
import com.maserb.monitor.entity.schoolNotice.SchoolNoticeEntity;
import com.maserb.monitor.entity.schoolStudent.SchoolStudentParentEntity;
import com.maserb.monitor.repository.personal.SchoolAdviseRepository;
import com.maserb.monitor.service.author_manage.UserService;
import com.maserb.monitor.service.base.IToolService;
import com.maserb.monitor.service.schoolNotice.SchoolNoticeService;
import com.maserb.monitor.service.schoolStudent.SchoolStudentParentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 意见反馈
 */
@Controller
@RequestMapping("/advise")
public class SchoolAdviseController {

    @Autowired
    SchoolAdviseRepository adviseRepository;

    @Autowired
    SchoolStudentParentService parentService;

    @Autowired
    UserService userService;

    /**
     * app
     * @param userId 用户id
     * @param content 反馈内容
     * @param contact 联系方式
     * @return
     */
    @RequestMapping("/saveParentAdvise")
    @ResponseBody
    public AjaxResult<Boolean> saveParentAdvise(String userId, String content, String contact) {
        return AjaxUtils.process(new Func_T<Boolean>() {
            @Override
            public Boolean invoke() throws Exception {
                SchoolAdviseEntity advise = new SchoolAdviseEntity();
                SchoolStudentParentEntity parent = parentService.findOne(userId);
                advise.setParent(parent);
                advise.setType("1");

                advise.setContact(contact);
                advise.setContent(content);

                adviseRepository.save(advise);
                return true;
            }
        });
    }

    /**
     * app
     * @param userId 用户id
     * @param content 反馈内容
     * @param contact 联系方式
     * @return
     */
    @RequestMapping("/saveTeacherAdvise")
    @ResponseBody
    public AjaxResult<Boolean> saveTeacherAdvise(String userId, String content, String contact) {
        return AjaxUtils.process(new Func_T<Boolean>() {
            @Override
            public Boolean invoke() throws Exception {
                SchoolAdviseEntity advise = new SchoolAdviseEntity();
                UserEntity teacher = userService.findOne(userId);
                advise.setTeacher(teacher);
                advise.setType("2");

                advise.setContact(contact);
                advise.setContent(content);

                adviseRepository.save(advise);
                return true;
            }
        });
    }
}
